package java3_20;

import java.util.Scanner;

//汽车业务类
public class Carbusiness {
    Scanner scanner = new Scanner(System.in);
    Car[] c = new Car[3];
    //租赁方法
    public void motoLeaseOut(String motoType){
        for (int i = 0; i < c.length; i++) {
            if (c[i]!=null){
                if (c[i].getCarNumber().equals(motoType)&&c[i].isFlag()){
                    System.out.println("租赁成功！");
                    c[i].setFlag(false);
                    c[i].showRentResult();
                    System.out.println("请输入要租赁的天数:");
                    int j = scanner.nextInt();
                    System.out.println("总金额为:"+c[i].calRent(j));
                    return;
                }
            }
        }
        System.out.println("租赁失败，无此车型可租！");
    }
public void show(String a){
    for (int i = 0; i <c.length ; i++) {
        if (c[i]!=null) {
            c[i].leaseOutFlow(a);
        }
        if (c[i]==null){
            return;
        }
    }
}
    //加新车方法
    public boolean add(Car car){

        for (int i = 0; i < c.length; i++) {
//            if (i==c.length-1){
//                Car[] c = new Car[b+10];
//            }
            if (c[i] == null) {
                    c[i] = car;
                    return true;
                }
        }
        return false;
    }

    //查看车辆情况方法
    public void show(){
        for (int i = 0; i < c.length; i++) {
            if (c[i] == null) {
                return;
            }
            Car car = c[i];
            car.show();

        }
    }
public void returnCar(String a){
    for (int i = 0; i <c.length ; i++) {
        if (c[i]!=null){
            if (c[i].getCarNumber().equals(a)&&!c[i].isFlag()){
                System.out.println("还车成功，下次继续合作！");
                c[i].setFlag(true);
                return;
            }
        }
    }
    System.out.println("归还失败请核对信息！");
}
public boolean Del(String a){
    for (int i = 0; i < c.length; i++) {
        if (c[i]==null){
            System.out.println("无此车型!");
            return false;
        }else {
            if (c[i].getCarNumber().equals(a)){
                if (i == c.length-1){
                    c[i] = null;
                    return true;
                }else {
                    for (int j = i+1; j < c.length; j++) {
                        c[j-1] = c[j];
                        if (j == c.length - 1) {
                            c[j] = null;
                        }
                    }
                    return true;
                }
            }
        }
    }
    System.out.println("没找到");
    return false;


}
}
